package com.itheima.app.controller;

import com.itheima.app.manager.UserPhoneManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserPhoneController {

    @Autowired
    UserPhoneManager userPhoneManager;


    /**
     * 发送验证码
     */
    @PostMapping("/users/phone/sendVerificationCode")
    public void sendVerificationCode(){
        userPhoneManager.sendVerificationCode();
    }


    /**
     * 校验验证码
     * @param
     * @return
     */
    @PostMapping("/users/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String,String> map){
        String verificationCode = map.get("verificationCode");
        return userPhoneManager.checkVerificationCode(verificationCode);
    }

    /**
     * 保存新手机号
     * @param
     * @return
     */
    @PostMapping("/users/phone")
    public ResponseEntity updatePhone(@RequestBody Map<String,String> map){
        String phone = map.get("phone");
        return userPhoneManager.setPhone(phone);
    }



}
